home *** CD-ROM | disk | FTP | other *** search
/ bioinformatics.org / bioinformatics.org_software.tar / www.bioinformatics.org / download / ecell2 / ecell220setup.exe / {app} / standard / SRCJ / Message.java < prev    next >
Text File  |  2002-07-02  |  5KB  |  199 lines

  1. /**
  2.  * title:     Message class (Message.java)<p>
  3.  * description  : Massage window class<p>
  4.  * Copyright (C) 1996-2001 Keio University <p>
  5.  * Copyright (C) 1998-2001 Japan Science and Technology Corporation (JST)<p>
  6.  * Copyright (C) 2000-2001 Mitsui Knowledge Industry Co. Ltd. Bioscience Division<p>
  7.  *               GNU General Public Licence <p>
  8.  * Division:     Mitsui Knowledge Industry Co. Ltd. Bioscience division <p>
  9.  * Version :     $Id: Message.java,v 1.6 2002/07/02 09:31:11 shiozawa Exp $ <p>
  10.  */
  11.  
  12.  
  13. package ecell;
  14.  
  15. import javax.swing.*;
  16. import java.awt.*;
  17. import java.awt.event.*;
  18. import java.util.Vector;
  19.  
  20. /**
  21.  * Class for displaying information on a simulation, being performed 
  22.  * @author:         XD.Zheng
  23.  * @version: 1.0
  24.  * @since JDK1.2.2
  25.  */
  26. public class Message extends JFrame implements ActionListener
  27. {
  28.     public static final int MSG_DEBUG = 4;
  29.     public static final int MSG_ATTEN = 3;
  30.     public static final int MSG_ERROR = 2;
  31.     public static final int MSG_LOG = 1;
  32.     
  33.     public static final int nMaxMessage = 1000;
  34.  
  35.     private final Color[] colorTable = {Color.black, Color.red, Color.red, Color.blue};
  36.  
  37.     Vector vecText = new Vector();
  38.  
  39.     JTextArea txaMessage = new JTextArea();
  40.     JPanel jp1 = new JPanel();
  41.     
  42.     // 2002.4  akira shiozawa
  43.     JButton buttonClose = new JButton( "Close" );
  44.     JButton buttonClear = new JButton( "Clear" );
  45.     JCheckBox chboxDebug = new JCheckBox( "show debug messages" );
  46.  
  47.     /**
  48.      * Constructor
  49.      */
  50.     public Message() {
  51.  
  52.         jbInit();
  53.     }
  54.  
  55.     /**
  56.      *Initialization
  57.      *@return void
  58.      *@exception  Exception
  59.      */
  60.     private void jbInit()
  61.     {
  62.         //this.setTitle("Messages");
  63.         this.setTitle("ECELL2 Console");
  64.         this.setSize(new Dimension(535, 470));
  65.         txaMessage.setAutoscrolls(true);
  66.         // 2002.4. akira shiozawa
  67.         txaMessage.setEditable( false );
  68.         
  69.         // 2002.4  akira shiozawa
  70.         JPanel jp11 = new JPanel();
  71.         jp11.setLayout( new FlowLayout( 0, 0, 0 ) );
  72.         jp11.add( buttonClose );
  73.         jp11.add( buttonClear );
  74.         
  75.         jp1.setLayout( new BorderLayout() );
  76.         jp1.add( jp11, "West" );
  77.         jp1.add( chboxDebug, "East" );
  78.  
  79.         JScrollPane jScrollPane = new JScrollPane(txaMessage);
  80.  
  81.         this.getContentPane().add(jScrollPane , BorderLayout.CENTER);
  82.         this.getContentPane().add( jp1, BorderLayout.SOUTH );
  83.  
  84.         this.setDefaultCloseOperation( WindowConstants.DO_NOTHING_ON_CLOSE );
  85.  
  86.         chboxDebug.addActionListener( this );
  87.         buttonClose.addActionListener( this );
  88.         buttonClear.addActionListener( this );
  89.  
  90.     }
  91.  
  92.  
  93.     public void actionPerformed( ActionEvent e )
  94.     {
  95.         if( e.getSource() == buttonClose )
  96.         {
  97.             exit_actionPerformed();
  98.         }
  99.         else if( e.getSource() == buttonClear )
  100.         {
  101.             txaMessage.setText( "" );
  102.         }
  103.         else if( e.getSource() == chboxDebug )
  104.         {
  105.             
  106.         }
  107.     }
  108.  
  109.     protected void processWindowEvent( WindowEvent e )
  110.     {
  111.         super.processWindowEvent( e );
  112.         if ( e.getID() == WindowEvent.WINDOW_CLOSING )
  113.         {
  114.             exit_actionPerformed();
  115.         }
  116.     }
  117.  
  118.     public void show()
  119.     {
  120.         super.show();
  121.         txaMessage.setCaretPosition( txaMessage.getText().length() );
  122.     }
  123.  
  124.     public void exit_actionPerformed()
  125.     {
  126.         this.hide();
  127.     }
  128.  
  129.     /*
  130.      *Set a message in the Massage window.
  131.      *@return           void
  132.      *@param message    Displayed message 
  133.      */
  134.     private void setMessage( String message, int flag, boolean lf )
  135.     {
  136.         /** 2002.7.2 comment out [not implemented yet]
  137.         if( vecText.size() >= Message.nMaxMessage )
  138.         {
  139.             vecText.remove( 0 );
  140.         }
  141.         vecText.addElement( (flag + ":" + message) );
  142.         **/
  143.         
  144.         if( flag == Message.MSG_DEBUG && !chboxDebug.isSelected() )
  145.         {
  146.             return;
  147.         }
  148.         
  149.         //txaMessage.setForeground( colorTable[flag - 1] );
  150.  
  151.         if( lf )
  152.         {
  153.             txaMessage.append(message + "\n");
  154.             System.out.println( message );
  155.         }
  156.         else
  157.         {
  158.             txaMessage.append( message );
  159.             System.out.print( message );
  160.         }
  161.         if( isShowing() )
  162.         {
  163.             txaMessage.setCaretPosition( txaMessage.getText().length() );
  164.         }
  165.         
  166.     }
  167.     
  168.     public void setMessage(String message)
  169.     {
  170.         setMessage( message, Message.MSG_LOG, true );
  171.     }
  172.     
  173.     public void setMessage( String message, boolean lf )
  174.     {
  175.         setMessage( message, Message.MSG_LOG, lf );
  176.     }
  177.     
  178.     public void setDebugMessage( String str )
  179.     {
  180.         setMessage( str, Message.MSG_DEBUG, true );
  181.     }
  182.     
  183.     public void setErrorMessage( Exception e )
  184.     {
  185.         setMessage( e.getMessage(), Message.MSG_ERROR, true );
  186.     }
  187.     
  188.     public void setAttentionMessage( String str )
  189.     {
  190.         setMessage( str, Message.MSG_ATTEN, true );
  191.     }
  192.     
  193.     public void setDebugFlag( boolean flag )
  194.     {
  195.         chboxDebug.setSelected( flag );
  196.     }
  197.  
  198. }
  199.